package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpContractsSearchPageUtil extends SeleniumPageUtil{
	public final static By CTS_SPAN_HEAD_TITLE = By.id("ctl44_hdrMain_lblHeader");
	public final static By CTS_LINK_SEARCH = By.xpath("//*[@id='ddcf634a-a5bf-4f11-9467-6e6d8e050e40']/a");
	public final static By CTS_LINK_CLEAR = By.xpath("//*[@id='dc8aa588-ce68-459b-a3a0-a7f5183bd3da']/a");
	public final static By CTS_TD_STATUS_CODE = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[1]/td[1]");
	public final static By CTS_CHECKBOX_ACTIVE = By.id("ctl44_chkActive");
	public final static By CTS_LABEL_ACTIVE = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[1]/td[2]/label[1]");
	public final static By CTS_CHECKBOX_PROGRESS = By.id("ctl44_chkInProgress");
	public final static By CTS_LABEL_PROGRESS = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[1]/td[2]/label[2]");
	public final static By CTS_CHECKBOX_CLOSED = By.id("ctl44_chkClosed");
	public final static By CTS_LABEL_CLOSED = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[1]/td[2]/label[3]");
	public final static By CTS_TD_CONTRACT_ID = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[2]/td[1]");
	public final static By CTS_INPUT_CONTRACT_ID = By.id("ctl44_txtContractID");
	public final static By CTS_TD_DESC = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[2]/td[3]");
	public final static By CTS_INPUT_DESC = By.id("ctl44_txtDescription");
	public final static By CTS_TD_NUMBER = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[2]/td[5]");
	public final static By CTS_INPUT_NUMBER = By.id("ctl44_txtPONumber");
	public final static By CTS_TD_SUPPLIER = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[3]/td[1]");
	public final static By CTS_SELECT_SUPPLIER = By.id("ctl44_cboSupplier");
	public final static By CTS_TD_SER_TYPE = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[3]/td[3]");
	public final static By CTS_SELECT_SER_TYPE = By.id("ctl44_cboServiceType");
	public final static By CTS_TD_OTHER_FIELD = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[4]/td[1]");
	public final static By CTS_SELECT_OTHER_FIELD = By.id("ctl44_cboOtherField");
	public final static By CTS_TD_OTHER_VALUE = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr[4]/td[3]");
	public final static By CTS_IMG_REFRESH = By.id("ctl44_ContractsReport_Header_imgRefresh");
//	public final static By CTS_IMG_REFRESH = By.id("ctl44_AssetReport_Header_imgRefresh");
	public final static By CTS_SPAN_RESULTS = By.id("ctl44_ContractsReport_ReportOutput");
	
	public static void enter(){
		SpHomePageUtil.enter();
		SpHomePageUtil.enterContractsSearch();
		waitForPageToLoad();
	}

	public static void waitForPageToLoad() {
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.selectFrame(SpHomePageUtil.HOME_FRAME_CONTENT_NAME);
		SeleniumUtil.waitOnElements(new By[]{
				CTS_CHECKBOX_ACTIVE,CTS_CHECKBOX_PROGRESS,CTS_CHECKBOX_CLOSED,CTS_INPUT_NUMBER,CTS_SELECT_OTHER_FIELD
		});
	}
	
	public static void waitForResultsRefresh() {
		boolean flag = !SeleniumUtil.findElements(CTS_IMG_REFRESH).get(0).getAttribute("style").toLowerCase().contains("display: none");
		long before = System.currentTimeMillis();
		while(flag){
			if((System.currentTimeMillis() - before) > 60 * 1000){
				SeleniumUtil.fail("more than 60 seconds no response!");
				return;
			}else{
				flag = !SeleniumUtil.findElements(CTS_IMG_REFRESH).get(0).getAttribute("style").toLowerCase().contains("display: none");
			}
		}
	}
}
